<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\batch;

use app\service\batch\ocean\MongoVideoStatusService;
use app\service\batch\ocean\product\ClueProductService;
use app\service\batch\ocean\product\ProductService;
use app\service\batch\ocean\VideoStatusService;

final class OceanBatchService extends BatchService
{
    /**
     * mongo修改视频删除状态.
     * @param int $accountId 账户表id
     * @param int $version 版本号日期
     */
    public static function batchMongoVideoStatus(int $accountId = 0, int $version = 0): bool
    {
        return MongoVideoStatusService::setMongoVideoStatus($accountId, $version);
    }

    /**
     * 修改视频删除状态.
     * @param string $advertiserId 广告主id
     * @param int $version 版本号日期
     */
    public static function batchVideoStatus(string $advertiserId = '', int $version = 0): bool
    {
        return VideoStatusService::setVideoStatus($advertiserId, $version);
    }

    /**
     * 产品删除.
     */
    public static function batchProductDel(string $advId = '', int $version = 0): bool
    {
        $key = ProductService::getBatchKey($advId);
        if (self::lock($key, $advId)) {
            $res = ProductService::batchProductDel($advId, $version);
            self::unlock($key);
            return $res;
        }
        return true;
    }

    /**
     * 线索产品删除.
     * @param int $accountId 账户ID
     * @param int $version 版本号
     * @return bool
     */
    public static function batchClueProductDel(int $accountId = 0, int $version = 0): bool
    {
        $key = ClueProductService::getBatchKey($accountId);
        if (self::lock($key, $accountId)) {
            $res = ClueProductService::batchClueProductDel($accountId, $version);
            self::unlock($key);
            return $res;
        }
        return true;
    }
}
